package com.workmanager.service;
import com.alibaba.druid.util.StringUtils;
import com.workmanager.bean.StudentBean;
import com.workmanager.bean.TeacherBean;
import com.workmanager.mapper.loginMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Lenovo on 2016/8/29.
 */
@Service("loginService")
public class loginService{
    private loginMapper loginmapper;

    /**
     * 得到学生的登录账户list
     * @return
     */
    public List<String> selectStudentNumber (){
        List<String> studentlist=new ArrayList<String>();
        studentlist=loginmapper.selectStudentNumber();
        return studentlist;
    }

    /**
     * 得到老师的登录的手机号
     * @return
     */
    public List<String> selectTeacherPhone (){
        List<String> teacherlist=new ArrayList<String>();
        teacherlist=loginmapper.selectTeacherPhone();
        return teacherlist;
    }

    /**
     * 得到学生的密码
     * @param studentnumber
     * @return
     */
    public String checkStudentPasswd(String studentnumber){
         return loginmapper.checkStudentPasswd(studentnumber);
    }

    /**
     * 得到老师的密码
     * @param phonenumber
     * @return
     */
    public String checkTeacherPasswd(String phonenumber){
        return loginmapper.checkTeacherPasswd(phonenumber);
    }

    /**
     * 判断该学生是否已经注册
     * true表示已经注册成功
     * @param studentlist
     * @param astudentnumber
     * @return
     */
    public boolean studentalready(List<String> studentlist,String astudentnumber){
        for (String anumber:studentlist) {
            if(StringUtils.equals(anumber,astudentnumber)){
                return true;
            }
        }
        return false;
    }

    /**
     * 判断该老师手机号收否已经注册
     * @param teacherlist
     * @param ateacherphone
     * @return
     */
    public boolean teacheralready(List<String> teacherlist,String ateacherphone){
        for (String ateacher:teacherlist) {
            if(StringUtils.equals(ateacher,ateacherphone)){
                return true;
            }
        }
        return false;
    }

    /**
     * 根据学生的登录的账户，得到该学生的name
     * @param studentphone
     * @return
     */
    public String getStudentNamebByPhone(String studentphone){
        return loginmapper.getStudentNamebByPhone(studentphone);
    }

    /**
     * 根据老师的账户得到老师的name
     * @param teacherphone
     * @return
     */
    public String getTeacherNameByphone(String teacherphone){
        return loginmapper.getTeacherNameByphone(teacherphone);
    }

    /**
     * 分别判断登录密码是否正确
     * @param getfromdatabase
     * @param jsppasswd
     * @return
     */
    public boolean teacherPasswd(String getfromdatabase,String jsppasswd){
        return StringUtils.equals(getfromdatabase,jsppasswd);
    }
    public boolean studentPasswd(String getfromdatabase,String jsppasswd){
        return StringUtils.equals(getfromdatabase,jsppasswd);
    }
    public TeacherBean selectaTeacherBean(String teacherphone){
        TeacherBean ateacherBean=loginmapper.selectaTeacherBean(teacherphone);
        return ateacherBean;
    }
    public StudentBean selectStudentBean(String studentnumber){
        StudentBean astudentBean=loginmapper.selectStudentBean(studentnumber);
        return astudentBean;

    }

    public loginMapper getLoginmapper() {
        return loginmapper;
    }

    public void setLoginmapper(loginMapper loginmapper) {
        this.loginmapper = loginmapper;
    }
}
